const TSNE = require("tsne-js");
const DATA_gaoshou = require("../test/210305-gaoshoudata.json");
const fs = require("fs-extra");
const path = require("path");
const lodash = require("lodash");
const DATA_tsne = require("../test/210303-pytsne-scaled.json");
const DATA_pca = require("../test/210305-pypca-scaled.json");
const DATA_tsnegaoshou = require("../test/210305-gaoshou-tsne.json");
const DATA_pcaGaoshou = require("../test/210305-gaoshou-pca.json")
// debugger
// let min = lodash.min(DATA2.map(e=>e.distance_to_others))

// return
// let DATA_gaoshou = DATA2.filter(e => e.is_gaoshou);

_ = (async () => {
  // await fs.writeFile(path.join(__dirname, "../test/210305-gaoshoudata.json"), JSON.stringify(DATA_gaoshou)) 
  debugger
  for (let i = 0; i < DATA_gaoshou.length; i++) {
    DATA_gaoshou[i]['tsne'] = DATA_tsnegaoshou[i];
    DATA_gaoshou[i]['pca'] = DATA_pcaGaoshou[i];
  }

  debugger
  await fs.writeFile(path.join(__dirname, "../test/210305-gaoshoudata+tsne+pca.json"), JSON.stringify(
    DATA_gaoshou
  )) 

})();




return;
// debugger
let model = new TSNE({
  dim: 2,
  perplexity: 30.0,
  earlyExaggeration: 4.0,
  learningRate: 100.0,
  nIter: 1000,
  metric: 'euclidean'
});
let ARRAR = DATA2
  // .slice(0, 500)
  .map(e => [e.distance_to_city_type_a,
  e.distance_to_city_type_b,
  e.distance_to_city_type_c,
  e.distance_to_city_type_d,
  e.distance_to_airline,
  e.distance_to_others,
  e.safetyzone_value
  ]);
debugger
model.init({
  data: ARRAR,
  type: "dense"
})

let [error, iter] = model.run();
debugger
// // rerun without re-calculating pairwise distances, etc.
// [error, iter] = model.rerun();

// `output` is unpacked ndarray (regular nested javascript array)
let output = model.getOutput();

// `outputScaled` is `output` scaled to a range of [-1, 1]
let outputScaled = model.getOutputScaled();
for (let i = 0; i < DATA2.length; i++) {
  DATA2[i]['tsne'] = outputScaled[i]
}
fs.writeFile(path.join(__dirname, "../test/210303tsneTest.json"), JSON.stringify(DATA2)).then(x => {
  debugger
  process.exit()
});

